home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ian & Stuart's Australian Mac 1993 September
/
clonecd
/
September 93.img
/
Archives
/
Decoration
/
Screensavers
/
Screen Savers
/
Darkness
/
dark.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-04-13
|
4KB
|
185 lines
/*
DARK - a simple screen saver application for the
"Darkness" Multifinder Screen Saver
written by Lunarmobiscuit Copyright 1989
*/
/* EVENT */
int done = FALSE; /* do event loop until done == TRUE */
int background = FALSE; /* flag for background or foreground */
/* WINDOW */
WindowPtr bigWindow; /* the window */
/* MENU */
MenuHandle appleMenu; /* Multifinder demands one menu */
/* OS DEFINES */
#define osEvt app4Evt
#define suspend 1
#define mouseMoved 0xFA
#define resumeMask 1
/* PROTOTYPES */
void EventLoop(void);
void do_blackout(long time);
int any_events(void);
void update_big(void);
void DoSuspend(EventRecord *theEvent);
void DoUpdate(EventRecord *theEvent);
void main(void);
extern void InitMacintosh(void);
extern void SetUpMenus(void);
extern int SetUpBigWindow(void);
/* main event loop */
void EventLoop(void)
{
int ok,any; /* flags used to check events */
EventRecord theEvent; /* the event record for Dark */
Point loc,old; /* current and last mouse position */
GetMouse(&old); /* initialize mouse position */
for(;!done;) {
if (!background) {
any = any_events(); /* are there any events in the queue? */
GetMouse(&loc); /* get the current mouse position */
/* check for cursor in the upper right corner (sleep now) */
if (loc.h > screenBits.bounds.right-3 && loc.h < screenBits.bounds.right+1 && loc.v > screenBits.bounds.top-1 && loc.v < screenBits.bounds.top+3)
done = FALSE;
/* did the mouse move? (5 pixels is more than bumping into the desk */
else if (old.h - loc.h > 3 || old.v - loc.v > 3 || loc.h - old.h > 3 || loc.v - old.v > 3)
done = TRUE;
/* are there any events? */
else if (any)
done = TRUE;
old = loc; /* save the current mouse location */
/**** ***/
/* INSERT YOUR CODE IN THE PROCEDURE do_blackout() */
/**** ***/
do_blackout(TickCount());
}
/* check the events to Dark */
/* 30L means Dark gets a null event at least every 30 ticks (i.e. 1/2 sec) */
ok = WaitNextEvent(everyEvent, &theEvent, 30L, 0L);
if (ok)
switch (theEvent.what)
{
case mouseDown:
case keyDown:
case autoKey:
done = TRUE;
break;
case updateEvt:
DoUpdate(&theEvent);
break;
case activateEvt:
break;
case osEvt:
DoSuspend(&theEvent);
break;
}
}
return;
}
/* the drawing routine goes in here */
void do_blackout(time)
long time; /* you can change the parameter to be whatever you wish */
{
/*
YOUR CODE GOES IN HERE
*/
return;
}
/* look through the event queue (low-mem global) */
int any_events(void)
{
int more = TRUE, any = FALSE;
EvQElPtr evt;
evt = (EvQElPtr)(EventQueue.qHead);
if (!evt) return(FALSE);
while (more) {
if (!evt || evt == (EvQElPtr)(EventQueue.qTail)) more = FALSE;
if (evt->evtQWhat != nullEvent) {
any = TRUE;
more = FALSE;
}
}
return(any);
}
/* draw the contents of the big window */
void update_big(void)
{
GrafPtr oldPort;
GetPort(&oldPort);
SetPort(bigWindow);
PenNormal();
PaintRect(&bigWindow->portRect);
SetPort(oldPort);
return;
}
/* multifinder (os) event */
void DoSuspend(theEvent)
EventRecord *theEvent;
{
switch ((theEvent->message >> 24) & 0xFF) {
case mouseMoved:
break;
case suspend:
background = (theEvent->message & resumeMask) ? 0 : 1;
/* Dark quits before of becoming a background program */
if (background) done = TRUE;
break;
}
return;
}
/* big window needs updating */
void DoUpdate(theEvent)
EventRecord *theEvent;
{
WindowPtr theWindow;
theWindow = (WindowPtr) theEvent->message;
BeginUpdate(theWindow);
update_big();
EndUpdate(theWindow);
return;
}
/* main code section */
void main(void)
{
int height = MBarHeight; /* remember menu bar height */
InitMacintosh(); /* initialize mac managers */
SetUpMenus(); /* must create a menu bar */
/* create the window and loop until event */
HideCursor();
if (SetUpBigWindow()) {
EventLoop();
MBarHeight = height;
}
ShowCursor();
ExitToShell(); /* th..th..that's all folks... */
}